<?php

class Log {

    protected $db = null;
	
    public function __construct($db) {
	$this->db = $db;
    }

    public function __destruct() {
	unset($this->db);
    }

	public function get_type_name($type){
		
		
	}


    /**
     * log记录

     * @param int $count	数量
     * @param int $uid   	用户id
     * @param string $user	用户名
     * @param string $type	类型
     * @param string $content   备注内容,可为空
     * @return bool
     */
    public function log($count, $id, $user, $type, $content = '', $main_id = '0') {
		global $cf_admin_info,$cf_user_info;
	$id = intval($id);
	$user = trim($user);
	$type = trim($type);
	$count = floatval($count);

	if ($id && $user && $type) {
	    switch ($type) {
		case "perfect_user_info":      //完善用户信息赠送积分		
		    $data = array(
			'log_uid' => $id,
			'log_user' => $user,
			'log_type' => $type,
			'log_score' => $count,
			'log_content' => $content,
			'log_create_time' => date("Y-m-d H:i:s")
		    );
			
		    $row = $this->db->insert('data_user_score_log', $data); //用户积分记录
		    $rs = $this->db->getInsertId();
		    break;
		case "user_score_change":     //积分调整
		    $data = array(
			'log_uid' => $id,
			'log_user' => $user,
			'log_type' => $type,
			'log_score' => $count,
			'log_content' => $content,
			'log_create_time' => date("Y-m-d H:i:s")
		    );
		    $row = $this->db->insert('data_user_score_log', $data);
		    $rs = $this->db->getInsertId();		   
		    if ($rs) {
			return true;
		    } else {
			return false;
		    }
		    break;		
	    }
	} else {
	    return false;
	}

	return $rs;
    }


	function get_sp_log($type,$where,$limit=20){
		$limit = intval($limit);
		switch($type){
			case "money":
				$table = "data_sp_money_log";
			break;	
			
		}
		
		$sql = "SELECT * FROM " . $table . " WHERE " . $where . " ORDER BY log_id desc ";
		if ($limit) {
			$sql .= " LIMIT " . $limit;
		}
		$data = $this->db->getAll($sql);
		return $data;	 
	}

	function get_goods_buy_log($where,$limit=0){
		$sql = "SELECT * FROM data_goods_buy_log WHERE " . $where . " ORDER BY gbl_id desc ";
		if ($limit) {
			$sql .= " LIMIT " . $limit;
		}
		$data = $this->db->getAll($sql);
		return $data;	

	}

	


}

?>